import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/pages/base/base_state.dart';
import 'package:flutter_shop/pages/category/category_tab_page/category_tab_contract.dart';
import 'package:flutter_shop/pages/category/category_tab_page/category_tab_presenter.dart';
import 'package:flutter_shop/pages/category/category_tab_page/entity/category_data.dart';
import 'package:flutter_shop/pages/category/category_tab_page/widget/left_menu.dart';
import 'package:flutter_shop/pages/category/category_tab_page/widget/right_plane.dart';
import 'package:flutter_shop/widget/common_app_bar.dart';
import 'package:flutter_shop/widget/page_state_widget.dart';

///分类tab
class CategoryTabPage extends StatefulWidget {
  @override
  _CategoryTabPageState createState() => _CategoryTabPageState();
}

class _CategoryTabPageState extends BaseState<CategoryTabPage, CategoryTabPresenter> with AutomaticKeepAliveClientMixin implements CategoryTabView {
  //分类数据
  List<CategoryData> mCategoryDatas = List();

  @override
  bool get wantKeepAlive => true;

  @override
  CategoryTabPresenter createPresenter() => CategoryTabPresenter();

  @override
  void buildComplete() {
    mPresenter.getCategoryData();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: CommonAppBar("分类", showBack: false),
      body: PageStateWidget(
        controller: pageStateController,
        retryClick: () {
          pageStateController.showLoading();
          mPresenter.getCategoryData();
        },
        child: Container(
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                width: ScreenUtil().setWidth(200),
                child: LeftMenu(mCategoryDatas), //左侧菜单
              ),
              Expanded(child: RightPlane()), //右侧面板
            ],
          ),
        ),
      ),
    );
  }

  @override
  void showPageData(List<CategoryData> list) {
    pageStateController.showSuccess();
    setState(() {
      mCategoryDatas.clear();
      mCategoryDatas.addAll(list);
    });
  }

  @override
  void showError(String str) {
    pageStateController.showError(str);
    showToast(str);
  }
}
